﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace MengCC.Common.IO
{
    public class DirectoryHelper
    {
        /// <summary>
        /// 设置文件为普通权限
        /// </summary>
        /// <param name="dir"></param>
        private static void SetFileAttributeAsNomal(string dir)
        {
            foreach (var item in Directory.GetFiles(dir))
            {
                File.SetAttributes(item, FileAttributes.Normal);
            }
            foreach (var item in Directory.GetDirectories(dir))
            {
                SetFileAttributeAsNomal(item);
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="project"></param>
        public static void RemoveAll(string dir)
        {
            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(dir);
                directoryInfo.Attributes = FileAttributes.Normal | FileAttributes.Hidden | FileAttributes.System;
                SetFileAttributeAsNomal(dir);
                if (directoryInfo.Exists) directoryInfo.Delete(true);
            }
            catch (Exception ex)
            {
                //log
            }
        }
    }
}
